package cn.com.cifi.mars.web.action.sys;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import cn.com.cifi.mars.bean.bo.SysLogBO;
import cn.com.cifi.mars.bean.vo.sys.req.UpdateMonitorConfigDetailReqParam;
import cn.com.cifi.mars.bean.vo.sys.rsp.MonitorConfigDetailVo;
import cn.com.cifi.mars.bean.vo.sys.rsp.MonitorDetailVo;
import cn.com.cifi.mars.common.base.BaseAction;
import cn.com.cifi.mars.common.bean.R;
import cn.com.cifi.mars.constant.LogEventEnum;
import cn.com.cifi.mars.constant.LogSrcEnum;
import cn.com.cifi.mars.entity.common.IdmUser;
import cn.com.cifi.mars.service.MonitorConfigDetailService;
import cn.com.cifi.mars.service.SysLogService;
import cn.com.cifi.mars.util.WebUtils;

/**
 * <p>
 * 监控设置明细 前端控制器
 * </p>
 *
 * @author plx
 * @since 2020-02-05
 */
@RestController
public class MonitorConfigDetailController extends BaseAction implements IMonitorConfigDetailController{

	@Autowired
	private MonitorConfigDetailService monitorConfigDetailService;
	@Autowired
	private SysLogService sysLogService;
	
	/**
	 * 根据组织机构id,查询监控标准信息
	 */
	@Override
	public R<List<MonitorConfigDetailVo>> getMonitorConfigDetailList(String apiVersion, String orgId) {
		return ok(monitorConfigDetailService.getMonitorConfigDetailList(orgId));
	}
	
	/**
	 * 编辑监控指标标准
	 */
	@Override
	public R<String> updateMonitorConfigDetail(String apiVersion, UpdateMonitorConfigDetailReqParam param) {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
		IdmUser user = getOperator();
		SysLogBO bo = new SysLogBO();
		bo.setEvent(LogEventEnum.EDIT);
		bo.setSource(LogSrcEnum.PC);
		bo.setIp(WebUtils.getIpAddr(request));
		bo.setUrl(WebUtils.getUrl(request));
		bo.setModule("系统管理");
		bo.setTitle("编辑监控指标标准");
		bo.setContent("编辑监控指标标准");
		sysLogService.add(bo,user.getAlias());
		return ok(monitorConfigDetailService.updateMonitorConfigDetail(param));
	}
	
	

	/**
	 * 根据监控详情id和组织机构id,查询监控标准详情
	 */
	@Override
	public R<MonitorDetailVo> getMonitorConfigDetail(String apiVersion, String orgId, String d1MonitorDetailId,
			String d2MonitorDetailId, String d3MonitorDetailId) {
		return ok(monitorConfigDetailService.getMonitorConfigDetail(orgId, d1MonitorDetailId, d2MonitorDetailId, d3MonitorDetailId));
	}

}
